<template>
	<view>
		<view class="flex justify-center items-center text-14 mb-5px" v-for="(item, _index) in MyList" :key="_index">
			<view class="w-150rpx h-150rpx flex-shrink-0">
				<u-image height="150rpx"  mode="aspectFit" class="sentence-img" :src="'https://nx5.abc5g.com'+item.Img"></u-image> 
			</view>
			<view style="flex:1; line-height: 30rpx;">
				<view style="padding-left: 10px;">
					<view>
						{{item.Title}}
						<text style="font-size: var(--text-12); color: #777;">兑换量:</text>{{item.Number}}个 
						<u-tag size="mini" type="success" :text="statusMap[item.Status]" shape="circle" />
					</view>
					<view>{{item.Name}} {{item.Phone}} {{item.Created.replace(/T/g,' ').split('.')[0]}}</view>
					<view>{{item.Address}}</view>
					<view>订单号:{{item.OrderNumber==null?'暂无':item.OrderNumber}}</view>
				</view> 
			</view>
			<view class="flex-shrink-0 w-100rpx">
				<u-button v-if="item.Status==2" @click="handleSignFor(item)" type="primary" plain size="mini">签收</u-button>
			</view>
		</view>
		<u-empty v-if="MyList.length == 0" text="暂无订单" mode="list"></u-empty>
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import { dateFormat, ktluser, ktlapi, getVersion,OT } from '@/utils';  
	
	 const user = ktluser.getUser(false)
	 const MyList = ref([]); 
	const statusMap = {
		0: '已下单',
		1: '待发货',
		2: '已发货',
		3: '已签收'
	}

	function handleSignFor(item) {
		uni.showModal({
			title: '提示',
			content: '你确定要签收该订单吗？',
			success: function(res) {
				if (res.confirm) {
					ktlapi({
						action: 'Cus_SignForOrder',
						data: {
							ID: item.ID
						}
					}).then(() => {
						item.Status = 3;
					})
				}
			}
		})
	}
	
	onMounted(() => {  
		uni.showLoading({
			title: '加载中'
		});
		ktlapi({ 
			apiurl:OT.CommandSet,
			action: "Cus_GetMyOrders",
			data: {
				"AccountId": user.AccountID
			}
		}).then(res => {
			MyList.value = res.data.tables[0].table; 
			uni.hideLoading();
		});
	})
</script>

<style lang="scss"> 
</style>